package com.itheima.controller;

import com.itheima.pojo.Question;
import com.itheima.pojo.Result;
import com.itheima.service.QuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("system")
@Slf4j
public class SystemController {

    @Autowired
    private QuestionService questionService;

    @PostMapping("/addQuestion")
    public Result AddQuestion(@RequestBody Question question){

        log.info("后台服务端接收到要添加的问答是: {}",question);
        if (null== question.getTitle()){
            return new Result(false,"问题不能为空");
        }
        questionService.addQuestion(question);
        return new Result(true,"添加问题成功");
    }
}
